﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using CVSA.Suporte.Sinacor.BMFBovespa.Negocio;
using CVSA.Suporte.Sinacor.BMFBovespa.Entidades;
using System.Configuration;

namespace CVSA.Suporte.Sinacor.BMFBovespa.ConsultaRemedy
{
    public partial class TaskForce : System.Web.UI.Page
    {
        private Remedy remedy = new Remedy();
        private int totalAline;
        private int totalPaula;
        private int totalPatricia;
        private int totalElen;
        private int totalMatheus;
        private int totalAlessandra;
        private int totalEunice;
        private int totalValdemar;
        

        protected void Page_Load(object sender, EventArgs e)
        {

            Response.Redirect("DesempenhoEquipe.aspx");
            Response.End();
            if (!Page.IsPostBack)
            {
                DataTable odt = remedy.getChamadosForcatarefa("01/01/2010", "31/01/2010");
                equipeA.DataSource = odt;
                equipeB.DataSource = odt;
                DataBind();
                lblMeta.Text = ConfigurationManager.AppSettings["qtMeta"];
            }
        }

        protected void formatRowEquipeA(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                DataRowView row = (DataRowView)e.Row.DataItem;
                Label lblTotalDia = (Label)e.Row.FindControl("lblTotalDia");
                lblTotalDia.Text = (Convert.ToInt32(row["Aline"]) + Convert.ToInt32(row["Elen"]) + Convert.ToInt32(row["Patricia"]) + Convert.ToInt32(row["Paula"])).ToString();

                totalAline += Convert.ToInt32(row["Aline"]);
                totalPatricia += Convert.ToInt32(row["Patricia"]);
                totalPaula += Convert.ToInt32(row["Paula"]);
                totalElen += Convert.ToInt32(row["Elen"]);

                if (Convert.ToInt32(lblTotalDia.Text) < Convert.ToInt32(ConfigurationManager.AppSettings["qtMeta"]))
                {
                    e.Row.Style.Add("background-color", "#990000");
                    e.Row.Style.Add("color", "#FFFFFF");
                }
            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblTotalAline = (Label)e.Row.FindControl("lblTotalAline");
                lblTotalAline.Text  = totalAline.ToString();

                Label lblTotalPaula = (Label)e.Row.FindControl("lblTotalPaula");
                lblTotalPaula.Text = totalPaula.ToString();

                Label lblTotalPatricia = (Label)e.Row.FindControl("lblTotalPatricia");
                lblTotalPatricia.Text = totalPatricia.ToString();

                Label lblTotalElen = (Label)e.Row.FindControl("lblTotalElen");
                lblTotalElen.Text = totalElen.ToString();


                Label lblTotalGeral = (Label)e.Row.FindControl("lblTotalGeral");
                lblTotalGeral.Text = (totalAline + totalPaula + totalPatricia + totalElen).ToString();

            }
            int TotalGeral = (totalValdemar + totalMatheus + totalEunice + totalAlessandra) + (totalAline + totalPaula + totalPatricia + totalElen);
            lblTot.Text = TotalGeral.ToString();
        }


        protected void formatRowEquipeB(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItem != null)
            {
                DataRowView row = (DataRowView)e.Row.DataItem;
                Label lblTotalDia = (Label)e.Row.FindControl("lblTotalDia");
                lblTotalDia.Text = (Convert.ToInt32(row["Alessandra"]) + Convert.ToInt32(row["Eunice"]) + Convert.ToInt32(row["Matheus"]) + Convert.ToInt32(row["Valdemar"])).ToString();

                totalAlessandra += Convert.ToInt32(row["Alessandra"]);
                totalEunice += Convert.ToInt32(row["Eunice"]);
                totalMatheus += Convert.ToInt32(row["Matheus"]);
                totalValdemar += Convert.ToInt32(row["Valdemar"]);

                if (Convert.ToInt32(lblTotalDia.Text) < Convert.ToInt32(ConfigurationManager.AppSettings["qtMeta"]))
                {
                    e.Row.Style.Add("background-color", "#990000");
                    e.Row.Style.Add("color", "#FFFFFF");
                }
            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblTotalAlessandra = (Label)e.Row.FindControl("lblTotalAlessandra");
                lblTotalAlessandra.Text = totalAlessandra.ToString();

                Label lblTotalEunice = (Label)e.Row.FindControl("lblTotalEunice");
                lblTotalEunice.Text = totalEunice.ToString();

                Label lblTotalMatheus= (Label)e.Row.FindControl("lblTotalMatheus");
                lblTotalMatheus.Text = totalMatheus.ToString();

                Label lblTotalValdemar = (Label)e.Row.FindControl("lblTotalValdemar");
                lblTotalValdemar.Text = totalValdemar.ToString();


                Label lblTotalGeral = (Label)e.Row.FindControl("lblTotalGeral");
                lblTotalGeral.Text = (totalValdemar + totalMatheus + totalEunice + totalAlessandra).ToString();

            }

          
        }
    }
}
